package com.jfreer.security;

import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

import java.util.*;

/**
 * User: landy
 * Date: 15/6/1
 * Time: 下午10:47
 */
@Service
public class SecurityData {
    public static final String ROLE_ADMIN = "admin";
    public static final String ROLE_VIEW = "view";
    private static Map<String, String> users = new HashMap<String, String>();
    private static MultiValueMap<String, String> roles = new LinkedMultiValueMap<String, String>();
    private static MultiValueMap<String, String> resources = new LinkedMultiValueMap<String, String>();

    static {
        /**账户信息**/
        users.put("root", "rootpass");
        users.put("landy", "landypass");


        /**角色信息**/
        roles.add("root", ROLE_ADMIN);
        roles.add("root", ROLE_VIEW);

        roles.add("landy", ROLE_VIEW);

        /**资源与角色**/
        resources.add("/test/jsp", ROLE_VIEW);
        resources.add("/test/jsp", ROLE_ADMIN);
        resources.add("/test/admin", ROLE_ADMIN);
        resources.add("/test", ROLE_VIEW);
        resources.add("/test", ROLE_ADMIN);
        resources.add("/test/index", ROLE_VIEW);
        resources.add("/test/index", ROLE_ADMIN);
    }

    public Collection<String> getRoleListByUrl(String requestUrl) {
        return resources.get(requestUrl);
    }

    public String findPassword(String name) {
        return users.get(name);
    }

    public List<String> getRoleListByUserName(String name) {
        return roles.get(name);
    }
}
